import { GSprite } from "../../../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../../../common/ObjCreate";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { Language } from "../../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { GuildEliteGroupGroup } from "./GuildEliteGroupGroup";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { DataEvent } from "../../../../events/DataEvent";
import { SGuildGroupPlayer } from "../../../../../../Message/Public/SGuildGroupPlayer";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { EventName } from "../../../../mvc/EventName";
import { Cache } from "../../../../cache/Cache";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { SGuildGroup } from "../../../../../../Message/Public/SGuildGroup";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { _group } from "../../../../../../this/_group";
type int = number;
//class GuildEliteGroupGroupPart
    
    export  class GuildEliteGroupGroupPart extends GSprite
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            ObjCreate.createBg(0, 0, 496, 390, this);
            ObjCreate.createBg(0, 2, 139, 24, this, ImagesConst.TileBg);
            this._bmTz = ObjCreate.createBitmap(null, 5, 5, this);
            this._tzName = ObjCreate.createGTextField("", 5, 5, 200, 20, this, new GTextFormat(FontUtil.defaultName, 12, 16776960, true), true, false);
            this._optBtn = ObjCreate.createGButton(Language.getString(60675), 415, 3, 75, 22, this);
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            this._optBtn.visible = false;
            this._group1 = this.createGroup(1, 4, 28);
            this._group2 = this.createGroup(2, 250, 28);
            this._group3 = this.createGroup(3, 4, 208);
            this._group4 = this.createGroup(4, 250, 208);
            this._openMask = new GSprite();
            this._openMask.buttonMode = true;
            this._openMask.mouseChildren = false;
            this._openMask.addEventListener(flash.events.MouseEvent.CLICK, this.onOpenBtnClickHandler);
            ObjCreate.createBg(0, 0, 496, 390, this._openMask);
            var loc1=GlobalStyle.getTextFormatCenter(GlobalStyle._textFormat6);
            loc1.font = FontUtil.stXingkaiName;
            loc1.size = 30;
            loc1.color = 16776960;
            ObjCreate.createGTextField(Language.getString(60673), 0, 190, 496, 50, this._openMask, loc1, true, false);
            return;
        }

        public onResLoaded(): void
        {
            this._bmTz.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildGroupText_tz);
            this._tzName.x = this._bmTz.x + this._bmTz.width + 5;
            return;
        }

        /* internal  */createGroup(arg1: int, arg2: int, arg3: int): GuildEliteGroupGroup
        {
            var loc1=null;
            (loc1 = new GuildEliteGroupGroup(arg1)).x = arg2;
            loc1.y = arg3;
            loc1.addEventListener(GModuleEvent.GuildGroup_MemberOptBtnClick, this.onMemberOptBtnClickHandler);
            loc1.addEventListener(GModuleEvent.GuildGroup_MemberSelectedChange, this.onMemberSelectedChangeHandler);
            loc1.addEventListener(GModuleEvent.GuildGroup_DoEnterGroup, this.onEnterGroupTextClickHandler);
            loc1.addEventListener(GModuleEvent.GuildGroup_ModifyTeamLeader, this.onModifyTeamLeaderClickHandler);
            this.addChild(loc1);
            return loc1;
        }

        /* internal  */onOpenBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_OpenGroupBtnClick));
            return;
        }

        /* internal  */onMemberOptBtnClickHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["data"] as SGuildGroupPlayer;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DoKickOutGroup, {"group": _group, "entityId": loc1.player.entityId, "name": loc1.player.name}));
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._curSelectedPlayer == null) 
            {
                return;
            }
            var loc1={"group": _group, "entityId": this._curSelectedPlayer.player.entityId, "name": this._curSelectedPlayer.player.name};
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DoModifyCommander, loc1));
            return;
        }

        /* internal  */onMemberSelectedChangeHandler(arg1: DataEvent): void
        {
            var loc2=null;
            this._curSelectedPlayer = arg1.data as SGuildGroupPlayer;
            var loc1=arg1.currentTarget as GuildEliteGroupGroup;
            var loc3=1;
            while (loc3 <= 4) 
            {
                loc2 = this["_group" + loc3] as GuildEliteGroupGroup;
                if (arg1.data == null || !(loc1 == loc2)) 
                {
                    loc2.selectedIndex = -1;
                }
                else 
                {
                    loc2.selectedMember = arg1.data as SGuildGroupPlayer;
                }
                ++loc3;
            }
            if (this._curSelectedPlayer && this.icanModifyCommander()) 
            {
                this._optBtn.visible = true;
            }
            else 
            {
                this._optBtn.visible = false;
            }
            return;
        }

        /* internal  */icanModifyCommander(): Boolean
        {
            if (Cache.instance.guild.isLeaderOrDeputyLeader) 
            {
                return true;
            }
            if (this._group && EntityUtil.equal(Cache.instance.role.entityInfo.entityId, this._group.commanderId)) 
            {
                return true;
            }
            return false;
        }

        /* internal  */onEnterGroupTextClickHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["pos"];
            var loc2=arg1.data["data"];
            var loc3;
            loc1 = ((loc3 = arg1.currentTarget as GuildEliteGroupGroup).index - 1) * 5 + loc1 + 1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DoEnterGroup, {"group": _group, "pos": loc1}));
            return;
        }

        /* internal  */onModifyTeamLeaderClickHandler(arg1: DataEvent): void
        {
            var loc1=arg1.currentTarget as GuildEliteGroupGroup;
            var loc2={"group": _group, "entityId": loc1.selectedMember.player.entityId, "name": loc1.selectedMember.player.name};
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DoModifyTeamLeader, loc2));
            return;
        }

        public updateCommander(arg1: string): void
        {
            this._tzName.htmlText = HTMLUtil.addColor(arg1, GlobalStyle.color6);
            return;
        }

        public set group(arg1: SGuildGroup)
        {
            this._group = arg1;
            if (this._group != null) 
            {
                if (this._openMask.parent) 
                {
                    this._openMask.parent.removeChild(this._openMask);
                }
            }
            else 
            {
                this.addChild(this._openMask);
            }
            return;
        }

        public updateData(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc1=null;
            if (arg1 == null) 
            {
                this._group1.updateDataProvider(new DataProvider());
                this._group2.updateDataProvider(new DataProvider());
                this._group3.updateDataProvider(new DataProvider());
                this._group4.updateDataProvider(new DataProvider());
                return;
            }
            var loc2=0;
            var loc3=arg1;
            for (loc1 in loc3) 
            {
                (this["_group" + loc1] as GuildEliteGroupGroup).updateDataProvider(arg1[loc1] as DataProvider);
            }
            return;
        }

        /* internal */ /* var */_bmTz: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tzName: GTextFiled;

        /* internal */ /* var */_optBtn: GButton;

        /* internal */ /* var */_curSelectedPlayer: SGuildGroupPlayer;

        /* internal */ /* var */_openMask: GSprite;

        /* internal */ /* var */_group1: GuildEliteGroupGroup;

        /* internal */ /* var */_group2: GuildEliteGroupGroup;

        /* internal */ /* var */_group3: GuildEliteGroupGroup;

        /* internal */ /* var */_group4: GuildEliteGroupGroup;

        /* internal */ /* var */_group: SGuildGroup;
    }
